import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:inmotion_pro/service/global_service.dart';

import 'avatar_view.dart';

class UserProfileCard extends StatelessWidget {
  final String avatarUrl;
  final String nickname;
  final String? subtitle; // 副标题
  final VoidCallback? onTap;
  final double avatarSize;
  final bool showEdit;
  final Color? backgroundColor;
  final EdgeInsetsGeometry? padding;

  const UserProfileCard({
    super.key,
    required this.avatarUrl,
    required this.nickname,
    this.subtitle,
    this.onTap,
    this.avatarSize = 40,
    this.showEdit = true,
    this.backgroundColor,
    this.padding = const EdgeInsets.all(16),
  });

  @override
  Widget build(BuildContext context) {
    return Material(
      color: backgroundColor ?? Colors.transparent,
      child: Container(
        padding: padding,
        child: Row(
          children: [
            AvatarView(
              avatarPath: avatarUrl,
              isLoggedIn: GlobalService.to.isLoggedIn,
              size: avatarSize,
            ),
            SizedBox(width: 12.w),
            Expanded(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    nickname,
                    style: const TextStyle(
                      fontSize: 24,
                      fontWeight: FontWeight.w500,
                    ),
                    maxLines: 1,
                    overflow: TextOverflow.ellipsis,
                  ),
                  if (subtitle != null) ...[
                    SizedBox(height: 4.w),
                    Text(
                      subtitle!,
                      style: TextStyle(
                        fontSize: 14,
                        color: Colors.grey[600],
                      ),
                      maxLines: 1,
                      overflow: TextOverflow.ellipsis,
                    ),
                  ],
                ],
              ),
            ),
            if (showEdit)
              InkWell(
                onTap: onTap,
                child: SizedBox(
                  child: Row(
                    children: [
                      SizedBox(width: 8.w),
                      Icon(
                        Icons.edit_note_sharp,
                        size: 26,
                        color: Colors.grey[400],
                      ),
                    ],
                  ),
                ),
              ),
          ],
        ),
      ),
    );
  }
}
